﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简单的web ping演示</title>
<script type="text/javascript" src="static/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function (){
	var ping, requestTime, responseTime ;
	setInterval(ping,1000);
	function ping() {
	$.ajax({url: 'empty.html',  //设置一个空的ajax请求
		type: 'GET',
		dataType: 'html',
		timeout: 30000,
		beforeSend : function() {
			requestTime = new Date().getTime();
		},
		complete : function() {
			responseTime = new Date().getTime();
			ping = Math.abs(requestTime - responseTime);
			$('#ping').append('<br />ping:' + ping + 'ms');
		}
	});
}
});

</script>
</head>

<body>
<div id="ping">loading...</div>
</body>
</html>